package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractEntity;
import com.moyuer.bsf.domain.model.User;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 预约分录
 *
 * @author 王睿智<geekrize@gmail.com>
 */
@Entity
@Table(name = "reserve_entry")
public class ReserveEntry extends AbstractEntity {

    @JSONField(serialize = false)
    @ManyToOne
    private Reserve owner; // 所属预约

    @JSONField(serialize = false)
    @ManyToOne
    private User from; // 发起人

    @JSONField(serialize = false)
    @ManyToOne
    private User to; // 接收人

    @NotNull
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "t_time")
    private Date time; // 预约时间

    @Column(unique = false, length = 60)
    private String remark; // 留言

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time", nullable = false, insertable = false, updatable = false)
    private Date createTime; // 创建时间

    @Transient
    private String fromId;
    @Transient
    private String fromName;
    @Transient
    private String toId;
    @Transient
    private String toName;

    public Reserve getOwner() {
        return owner;
    }

    public void setOwner(Reserve owner) {
        this.owner = owner;
    }

    public User getFrom() {
        return from;
    }

    public void setFrom(User from) {
        this.from = from;
    }

    public User getTo() {
        return to;
    }

    public void setTo(User to) {
        this.to = to;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getFromId() {
        if (fromId != null) {
            return fromId;
        }

        if (from != null) {
            fromId = from.getId();
        }

        return fromId;
    }

    public void setFromId(String fromId) {
        this.fromId = fromId;
    }

    public String getFromName() {
        if (fromName != null) {
            return fromName;
        }

        if (from != null) {
            fromName = from.getName();
        }

        return fromName;
    }

    public void setFromName(String fromName) {
        this.fromName = fromName;
    }

    public String getToId() {
        if (toId != null) {
            return toId;
        }

        if (to != null) {
            toId = to.getId();
        }

        return toId;
    }

    public void setToId(String toId) {
        this.toId = toId;
    }

    public String getToName() {
        if (toName != null) {
            return toName;
        }

        if (to != null) {
            toName = to.getName();
        }

        return toName;
    }

    public void setToName(String toName) {
        this.toName = toName;
    }
}
